<?php

namespace App\Services\PolicyUpload;

class CtripService
{

    /**
     * 处理携程数据
     * @param $param
     * @return void
     */
    public static function CtripDataSet(&$param){

        //处理提前预订天数
        if (!empty($param['AdvanceDay'])) {

            $advances = explode('-',$param['AdvanceDay']);
            if ($advances && count($advances) == 2) {

                $param['AdvanceDay']    = $advances[0];
                $param['MaxAdvanceDay'] = $advances[1];
            }
        }

        //处理停留天数
        if (!empty($param['StopDay'])) {

            $stopDays = explode('-',$param['StopDay']);
            if ($advances && count($advances) == 2) {

                $param['MinStopDay']    = $stopDays[0];
                $param['MaxStopDay']    = $stopDays[1];
            }
        }
    }

    /**
     * 上传政策参数转化 携程
     * @param $param
     */
    public static function platformUpload($param) {

        $item['Class']                       = 'Y'; //F：头等舱 C:公务舱  Y:经济舱
        $item['AdvanceDay']                  = 0;
        $item['MaxAdvanceDay']               = 365;
        $item['PolicyCode']                  = $param['policy_code'];
        $item['AirLine']                     = $param['hs_code'];
        $item['FlightWay']                   = 'S';
        $item['ApplyChild']                  = 'T';
        $item['OfficeNo']                    = null;
        $item['DepartPort']                  = $param['depart_city_code'];
        $item['ArrivePort']                  = $param['arrived_city_code'];
        $item['EffectDate']                  = $param['startSellDate'];
        $item['ExpiryDate']                  = $param['endSellDate'];
        $item['IsValid']                     = $param['status'] == 1 ? 'T' : 'F';
        $item['ProductType']                 = 'BJ';
        $item['InventoryType']               = $param['InventoryType'];
        $item['GoEffectDate']                = $param['date'];
        $item['GoExpiryDate']                = $param['date'];
        $item['IsCompositionPrice']          = false;
        $item['PrintPrice']                  = 0;
        $item['SetPrice']                    = $param['set_price'];
        $item['BiddingSpace']                = $param['cabin_price'];
        $item['BookingThreshold']            = 0;
        $item['IDLimit']                     = 'F';
        $item['TicketInventory']             = $param['seat'];
        $item['IsReturnRefundInventory']     = 'F';
        $item['IsBooking']                   = 'F';
        $item['IATANo']                      = '08309722';
        if ($param['platform'] == 10) {
            $item['RcID'] = '12410623';
        } else {
            $item['RcID'] = '12730243';
        }
        $item['SubClass']                    = $param['cabin_code'];
        $item['RuleDetail']                  = $param['flight_code'];
//        dd($item);
        return $item;
    }
}